<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">

    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">产品名称</label>
        <div class="layui-input-block">
            <input name="productName" class="layui-input" placeholder="请输入产品名称" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">序列号</label>
        <div class="layui-input-block">
            <input name="serialNumber" class="layui-input" placeholder="请输入序列号" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">客户姓名</label>
        <div class="layui-input-block">
            <input name="customerName" class="layui-input" placeholder="请输入客户姓名" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修记录拍照</label>
        <div class="layui-input-block">
            <input class="layui-input" type="hidden" name="photo" id="cover"/>
            <button id="file-btn-upload" class="layui-btn layui-btn-sm layui-btn-normal icon-btn">
                <i class="layui-icon">&#xe681;</i>上传文件
            </button>
            <p id="demoText"></p>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修工人</label>
        <div class="layui-input-block">
            <input name="repairWorker" class="layui-input" placeholder="请输入维修工人" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修日期</label>
        <div class="layui-input-block">
            <input type="text" name="repairDate" id="repairDateId" placeholder="请选择维修日期" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修费用</label>
        <div class="layui-input-block">
            <input type="text" name="repairCost" id="repairCostId" placeholder="请选择维修费用" lay-verify="number" autocomplete="off" class="layui-input">

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修描述</label>
        <div class="layui-input-block">
            <input name="repairDescription" class="layui-input" placeholder="请输入维修描述" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;
        var upload = layui.upload;

        laydate.render({
            elem: '#repairDateId'
        });

        // 上传
        upload.render({
            elem: '#file-btn-upload',
            accept: 'images',
            url: getProjectUrl() + 'sysFileInfo/upload',
            done: function(res){
                handleNetworkError(res);
                console.log(res);
                if(res.success) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {

                        //上传成功
                        var demoText = $('#demoText');
                        demoText.html('<span style="color: #206bc4;">上传成功</span>');
                        var coverUpload = $("#cover");
                        coverUpload.attr('value',res.data+"."+res.suffix);//给隐藏输入框复制
                    });
                }
            }
        });

        var editData = admin.getLayerData('#addOrUpdateForm').data;
        if(editData !== null && editData !== undefined) {
            form.val('addOrUpdateForm', editData);
        }

        /**
         * 表单提交事件
         */
        form.on('submit(formSubmitBtn)', function (data) {
            layer.load(2);

            var url = editData ? getProjectUrl() + 'maintenanceRecords/edit' : getProjectUrl() + 'maintenanceRecords/add';
            admin.req(url, JSON.stringify(data.field), function(res){
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            return false;
        });
    });
</script>
</body>
</html>
